<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加用户 - 1024导航后台</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#3B82F6',
                        secondary: '#1024nav',
                        accent: '#F59E0B',
                        dark: '#1F2937',
                        light: '#F9FAFB',
                        danger: '#EF4444'
                    },
                    fontFamily: {
                        sans: ['Inter', 'system-ui', 'sans-serif'],
                    },
                }
            }
        }
    </script>
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
            .sidebar-active {
                @apply bg-primary/10 text-primary border-l-4 border-primary;
            }
            .form-input-focus {
                @apply focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary;
            }
        }
    </style>
</head>

<body class="bg-gray-50 font-sans text-gray-800 flex h-screen overflow-hidden">
    <!-- 侧边栏导航 -->
    <aside
        class="w-64 bg-white shadow-sm h-full border-r border-gray-200 flex-shrink-0 hidden md:block overflow-y-auto">
        <div class="p-5 border-b border-gray-200">
            <div class="text-primary text-xl font-bold">1024<span class="text-secondary">导航</span></div>
            <p class="text-xs text-gray-500 mt-1">管理员后台</p>
        </div>

        <nav class="p-4">
            <p class="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-3 px-3">主菜单</p>
            <ul class="space-y-1">
                <li>
                    <a href="admin_index.html"
                        class="flex items-center px-3 py-3 text-sm text-gray-700 hover:bg-gray-50 rounded-md transition-colors">
                        <i class="fa fa-tachometer w-5 text-center mr-3"></i>
                        <span>控制台</span>
                    </a>
                </li>
                <li>
                    <a href="admin_resource_manager.html"
                        class="flex items-center px-3 py-3 text-sm text-gray-700 hover:bg-gray-50 rounded-md transition-colors">
                        <i class="fa fa-th-large w-5 text-center mr-3"></i>
                        <span>资源管理</span>
                    </a>
                </li>
                <li>
                    <a href="#"
                        class="flex items-center px-3 py-3 text-sm text-gray-700 hover:bg-gray-50 rounded-md transition-colors">
                        <i class="fa fa-wrench w-5 text-center mr-3"></i>
                        <span>工具管理</span>
                    </a>
                </li>
                <li>
                    <a href="#" class="sidebar-active flex items-center px-3 py-3 text-sm rounded-md">
                        <i class="fa fa-users w-5 text-center mr-3"></i>
                        <span>用户管理</span>
                    </a>
                </li>
                <li>
                    <a href="#"
                        class="flex items-center px-3 py-3 text-sm text-gray-700 hover:bg-gray-50 rounded-md transition-colors">
                        <i class="fa fa-comments w-5 text-center mr-3"></i>
                        <span>社区内容</span>
                    </a>
                </li>
                <li>
                    <a href="#"
                        class="flex items-center px-3 py-3 text-sm text-gray-700 hover:bg-gray-50 rounded-md transition-colors">
                        <i class="fa fa-bar-chart w-5 text-center mr-3"></i>
                        <span>数据统计</span>
                    </a>
                </li>
            </ul>

            <p class="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-3 px-3 mt-8">系统设置</p>
            <ul class="space-y-1">
                <li>
                    <a href="#"
                        class="flex items-center px-3 py-3 text-sm text-gray-700 hover:bg-gray-50 rounded-md transition-colors">
                        <i class="fa fa-cog w-5 text-center mr-3"></i>
                        <span>网站设置</span>
                    </a>
                </li>
                <li>
                    <a href="#"
                        class="flex items-center px-3 py-3 text-sm text-gray-700 hover:bg-gray-50 rounded-md transition-colors">
                        <i class="fa fa-shield w-5 text-center mr-3"></i>
                        <span>安全设置</span>
                    </a>
                </li>
                <li>
                    <a href="#"
                        class="flex items-center px-3 py-3 text-sm text-gray-700 hover:bg-gray-50 rounded-md transition-colors">
                        <i class="fa fa-bell w-5 text-center mr-3"></i>
                        <span>通知管理</span>
                    </a>
                </li>
            </ul>
        </nav>
    </aside>

    <!-- 主内容区 -->
    <div class="flex-1 flex flex-col overflow-hidden">
        <!-- 顶部导航 -->
        <header class="bg-white shadow-sm h-16 border-b border-gray-200 flex items-center justify-between px-6">
            <div class="flex items-center">
                <button class="md:hidden mr-4 text-gray-600">
                    <i class="fa fa-bars text-xl"></i>
                </button>
                <h1 class="text-lg font-semibold">添加用户</h1>
            </div>

            <div class="flex items-center space-x-4">
                <div class="relative">
                    <button class="text-gray-600 hover:text-primary transition-colors relative">
                        <i class="fa fa-bell text-xl"></i>
                        <span
                            class="absolute -top-1 -right-1 w-4 h-4 bg-danger rounded-full text-white text-xs flex items-center justify-center">3</span>
                    </button>
                </div>

                <div class="relative group">
                    <button class="flex items-center space-x-2">
                        <img src="https://picsum.photos/id/1005/40/40" alt="管理员头像"
                            class="w-8 h-8 rounded-full object-cover">
                        <span class="text-sm font-medium hidden md:inline-block">管理员</span>
                        <i class="fa fa-angle-down text-gray-500"></i>
                    </button>
                    <div
                        class="absolute right-0 mt-2 w-48 bg-white rounded-lg shadow-lg py-2 z-10 hidden group-hover:block">
                        <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">个人资料</a>
                        <a href="#" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">账号设置</a>
                        <div class="border-t border-gray-100 my-1"></div>
                        <a href="#" class="block px-4 py-2 text-sm text-red-600 hover:bg-gray-100">退出登录</a>
                    </div>
                </div>
            </div>
        </header>

        <!-- 页面内容 -->
        <main class="flex-1 overflow-y-auto p-6 bg-gray-50">
            <div class="max-w-3xl mx-auto">
                <!-- 操作栏 -->
                <div class="bg-white rounded-xl shadow-sm p-4 mb-6 flex justify-between items-center">
                    <div class="flex items-center">
                        <a href="admin_user_manager.html" class="text-gray-600 hover:text-primary transition-colors">
                            <i class="fa fa-arrow-left mr-1"></i> 返回用户列表
                        </a>
                    </div>
                    <div>
                        <button type="button"
                            class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 transition-colors mr-2">
                            取消
                        </button>
                        <button type="submit" form="addUserForm"
                            class="px-4 py-2 bg-primary text-white rounded-md hover:bg-primary/90 transition-colors">
                            <i class="fa fa-save mr-1"></i> 保存用户
                        </button>
                    </div>
                </div>

                <!-- 添加用户表单 -->
                <div class="bg-white rounded-xl shadow-sm p-6 mb-6">
                    <h2 class="text-lg font-semibold mb-6 pb-3 border-b border-gray-100">基本信息</h2>

                    <form id="addUserForm" class="space-y-6">
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                            <div>
                                <label for="username" class="block text-sm font-medium text-gray-700 mb-1">用户名 <span
                                        class="text-danger">*</span></label>
                                <input type="text" id="username" name="username" required
                                    class="w-full px-4 py-2 border border-gray-300 rounded-md form-input-focus"
                                    placeholder="请输入用户名">
                                <p class="text-xs text-gray-500 mt-1">用户名由3-20个字符组成，支持字母、数字和下划线</p>
                            </div>

                            <div>
                                <label for="email" class="block text-sm font-medium text-gray-700 mb-1">电子邮箱 <span
                                        class="text-danger">*</span></label>
                                <input type="email" id="email" name="email" required
                                    class="w-full px-4 py-2 border border-gray-300 rounded-md form-input-focus"
                                    placeholder="请输入电子邮箱">
                                <p class="text-xs text-gray-500 mt-1">将用于登录和接收系统通知</p>
                            </div>
                        </div>

                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                            <div>
                                <label for="password" class="block text-sm font-medium text-gray-700 mb-1">密码 <span
                                        class="text-danger">*</span></label>
                                <input type="password" id="password" name="password" required
                                    class="w-full px-4 py-2 border border-gray-300 rounded-md form-input-focus"
                                    placeholder="请设置密码">
                                <p class="text-xs text-gray-500 mt-1">密码长度至少8位，包含字母和数字</p>
                            </div>

                            <div>
                                <label for="confirmPassword" class="block text-sm font-medium text-gray-700 mb-1">确认密码
                                    <span class="text-danger">*</span></label>
                                <input type="password" id="confirmPassword" name="confirmPassword" required
                                    class="w-full px-4 py-2 border border-gray-300 rounded-md form-input-focus"
                                    placeholder="请再次输入密码">
                            </div>
                        </div>

                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                            <div>
                                <label for="nickname" class="block text-sm font-medium text-gray-700 mb-1">昵称</label>
                                <input type="text" id="nickname" name="nickname"
                                    class="w-full px-4 py-2 border border-gray-300 rounded-md form-input-focus"
                                    placeholder="请输入昵称">
                            </div>

                            <div>
                                <label for="role" class="block text-sm font-medium text-gray-700 mb-1">用户角色 <span
                                        class="text-danger">*</span></label>
                                <select id="role" name="role" required
                                    class="w-full px-4 py-2 border border-gray-300 rounded-md form-input-focus">
                                    <option value="">请选择角色</option>
                                    <option value="user">普通用户</option>
                                    <option value="contributor">内容贡献者</option>
                                    <option value="moderator">内容审核员</option>
                                    <option value="admin">管理员</option>
                                </select>
                            </div>
                        </div>

                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-3">用户头像</label>
                            <div class="flex items-center space-x-4">
                                <div
                                    class="w-20 h-20 rounded-full bg-gray-100 flex items-center justify-center overflow-hidden">
                                    <img id="avatarPreview" src="https://picsum.photos/id/1005/200/200" alt="用户头像"
                                        class="w-full h-full object-cover">
                                </div>
                                <div>
                                    <button type="button"
                                        class="px-4 py-2 bg-gray-100 text-gray-700 rounded-md hover:bg-gray-200 transition-colors mr-2">
                                        <i class="fa fa-upload mr-1"></i> 上传头像
                                    </button>
                                    <input type="file" id="avatar" name="avatar" accept="image/*" class="hidden">
                                    <p class="text-xs text-gray-500 mt-2">支持JPG、PNG格式，建议尺寸200x200px</p>
                                </div>
                            </div>
                        </div>

                        <div>
                            <label for="bio" class="block text-sm font-medium text-gray-700 mb-1">个人简介</label>
                            <textarea id="bio" name="bio" rows="3"
                                class="w-full px-4 py-2 border border-gray-300 rounded-md form-input-focus"
                                placeholder="请输入个人简介（可选）"></textarea>
                            <p class="text-xs text-gray-500 mt-1">最多输入200个字符</p>
                        </div>

                        <div class="pt-4 border-t border-gray-100">
                            <label class="flex items-center">
                                <input type="checkbox" name="sendWelcomeEmail"
                                    class="rounded border-gray-300 text-primary focus:ring-primary">
                                <span class="ml-2 text-sm text-gray-700">发送欢迎邮件给用户</span>
                            </label>
                        </div>
                    </form>
                </div>

                <!-- 账号设置 -->
                <div class="bg-white rounded-xl shadow-sm p-6">
                    <h2 class="text-lg font-semibold mb-6 pb-3 border-b border-gray-100">账号设置</h2>

                    <div class="space-y-6">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-3">账号状态</label>
                            <div class="flex items-center space-x-6">
                                <label class="flex items-center">
                                    <input type="radio" name="status" value="active" checked
                                        class="text-primary focus:ring-primary">
                                    <span class="ml-2 text-sm text-gray-700">启用</span>
                                </label>
                                <label class="flex items-center">
                                    <input type="radio" name="status" value="inactive"
                                        class="text-primary focus:ring-primary">
                                    <span class="ml-2 text-sm text-gray-700">禁用</span>
                                </label>
                                <label class="flex items-center">
                                    <input type="radio" name="status" value="pending"
                                        class="text-primary focus:ring-primary">
                                    <span class="ml-2 text-sm text-gray-700">待验证</span>
                                </label>
                            </div>
                        </div>

                        <div>
                            <label for="joinDate" class="block text-sm font-medium text-gray-700 mb-1">注册日期</label>
                            <input type="date" id="joinDate" name="joinDate"
                                class="w-full px-4 py-2 border border-gray-300 rounded-md form-input-focus">
                            <p class="text-xs text-gray-500 mt-1">默认为当前日期</p>
                        </div>

                        <div>
                            <label class="block text-sm font-medium text-gray-700 mb-3">权限设置</label>
                            <div class="grid grid-cols-1 md:grid-cols-2 gap-3">
                                <label class="flex items-center">
                                    <input type="checkbox" name="permissions[]" value="submit_resource" checked
                                        class="rounded border-gray-300 text-primary focus:ring-primary">
                                    <span class="ml-2 text-sm text-gray-700">提交资源</span>
                                </label>
                                <label class="flex items-center">
                                    <input type="checkbox" name="permissions[]" value="post_comment" checked
                                        class="rounded border-gray-300 text-primary focus:ring-primary">
                                    <span class="ml-2 text-sm text-gray-700">发表评论</span>
                                </label>
                                <label class="flex items-center">
                                    <input type="checkbox" name="permissions[]" value="create_topic" checked
                                        class="rounded border-gray-300 text-primary focus:ring-primary">
                                    <span class="ml-2 text-sm text-gray-700">创建主题</span>
                                </label>
                                <label class="flex items-center">
                                    <input type="checkbox" name="permissions[]" value="upload_file"
                                        class="rounded border-gray-300 text-primary focus:ring-primary">
                                    <span class="ml-2 text-sm text-gray-700">上传文件</span>
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
    </div>

    <!-- 回到顶部按钮 -->
    <button id="backToTop"
        class="fixed bottom-6 right-6 w-12 h-12 rounded-full bg-primary text-white shadow-lg flex items-center justify-center opacity-0 invisible transition-all duration-300">
        <i class="fa fa-arrow-up"></i>
    </button>

    <script>
        // 回到顶部按钮功能
        const backToTopBtn = document.getElementById('backToTop');

        window.addEventListener('scroll', () => {
            if (window.scrollY > 300) {
                backToTopBtn.classList.remove('opacity-0', 'invisible');
                backToTopBtn.classList.add('opacity-100', 'visible');
            } else {
                backToTopBtn.classList.remove('opacity-100', 'visible');
                backToTopBtn.classList.add('opacity-0', 'invisible');
            }
        });

        backToTopBtn.addEventListener('click', () => {
            window.scrollTo({
                top: 0,
                behavior: 'smooth'
            });
        });

        // 头像上传预览
        const avatarInput = document.getElementById('avatar');
        const avatarPreview = document.getElementById('avatarPreview');
        const uploadBtn = document.querySelector('button:has(.fa-upload)');

        uploadBtn.addEventListener('click', () => {
            avatarInput.click();
        });

        avatarInput.addEventListener('change', (e) => {
            const file = e.target.files[0];
            if (file) {
                const reader = new FileReader();
                reader.onload = (event) => {
                    avatarPreview.src = event.target.result;
                };
                reader.readAsDataURL(file);
            }
        });

        // 表单验证
        const addUserForm = document.getElementById('addUserForm');
        const password = document.getElementById('password');
        const confirmPassword = document.getElementById('confirmPassword');

        addUserForm.addEventListener('submit', (e) => {
            if (password.value !== confirmPassword.value) {
                e.preventDefault();
                alert('两次输入的密码不一致');
                confirmPassword.focus();
                return false;
            }

            // 可以添加更多验证逻辑

            // 提交成功后跳转到用户列表页
            // e.preventDefault();
            // window.location.href = 'admin_user_manager.html';
        });
    </script>
</body>

</html>